import {getcates} from '../../utils/api'
const state={
    list:[],
    twolist:[]
}

const mutations={
    changelist(state,arr){
        state.list=arr
    },
    changetwolist(state,arr){
        state.twolist=arr
    }
}

const actions={
    reqchangelist(context){
        getcates().then(res=>{
            context.commit('changelist',res.data.list)
            context.commit('changetwolist',res.data.list[0].children)
            // console.log(res.data.list[0].children);
        })
    },
    reqchangetwolist(context,index){
        let list=context.state.list[index].children?context.state.list[index].children:[];
        context.commit('changetwolist',list)
    }
}

const getters={
    list(state){
        return state.list
    },
    twolist(state){
        return state.twolist
    }
}

export default{
    state,
    mutations,
    actions,
    getters,
    namespaced: true
}